package com.xinchuang.service.impl;


import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinchuang.comment.R;
import com.xinchuang.domain.entity.DictTable;
import com.xinchuang.domain.entity.TestImage;
import com.xinchuang.domain.entity.TestModelParam;
import com.xinchuang.domain.entity.TestModelSubTable;
import com.xinchuang.domain.pojo.TryOutDeviceMod;
import com.xinchuang.domain.vo.TestModelParamToVo;
import com.xinchuang.domain.vo.TestModelParamVo;
import com.xinchuang.entity.Edtion;
import com.xinchuang.entity.api.OaUserParam;
import com.xinchuang.manager.DictTableService;
import com.xinchuang.manager.TestImageService;
import com.xinchuang.manager.TestModelParamService;
import com.xinchuang.manager.TestModelSubTableService;
import com.xinchuang.mapper.TestImageMapper;
import com.xinchuang.role.entity.SystemHeader;
import com.xinchuang.service.MoldManagementModService;
import com.xinchuang.service.OaUserService;
import com.xinchuang.service.actual.EdtionService;
import com.xinchuang.service.actual.TryOutDeviceModService;
import com.xinchuang.utils.EdtionVerity;
import com.xinchuang.utils.MyUtils;
import com.xinchuang.utils.ObjectUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class MoldManagementModServiceImpl implements MoldManagementModService {

    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Autowired
    private TestModelParamService testModelParamService;

    @Autowired
    private TestModelSubTableService testModelSubTableService;

    @Autowired
    private EdtionService edtionService;

    @Autowired
    private DictTableService dictTableService;

    @Autowired
    private TryOutDeviceModService tryOutDeviceModService;

    @Autowired
    private OaUserService oaUserService;
    @Autowired
    private TestImageService testImageService;
    @Autowired
    private TestImageMapper testImageMapper;

    @Override
    public String moldList(JSONObject jsonObject) {
        //jsonobject解析获取模具编号
        String moldId = jsonObject.getString("moldId");
        //jsonobject解析获取模具名称
        String moldName = jsonObject.getString("moldName");
        //jsonobject解析获取页码
        String pageNum = jsonObject.getString("pageNum");
        //jsonobject解析获取每页数量
        String pageSize = jsonObject.getString("pageSize");
        //jsonobject解析获取钳工
        String tongmanName = jsonObject.getString("tongmanName");

        String projectName = jsonObject.getString("projectName");

        String projectManager = jsonObject.getString("projectManager");

        Page<TestModelParam> testModelParamPage = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
        LambdaQueryWrapper<TestModelParam> testModelParamLambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(moldName)) {
            testModelParamLambdaQueryWrapper.like(TestModelParam::getMoldName, moldName);
        }
        if (StringUtils.isNotBlank(moldId)) {
            testModelParamLambdaQueryWrapper.like(TestModelParam::getMoldId, moldId);
        }
        if (StringUtils.isNotBlank(tongmanName)) {
            List<OaUserParam> params = oaUserService.lambdaQuery().like(OaUserParam::getName, tongmanName).list();
            if (CollectionUtil.isNotEmpty(params)) {
                List<String> tn = new ArrayList<>();
                for (OaUserParam param : params) {
                    tn.add(param.getId() + "");
                }
                testModelParamLambdaQueryWrapper.in(TestModelParam::getTongmanName, tn);
            }
        }
        if (StringUtils.isNotBlank(projectName)) {
            testModelParamLambdaQueryWrapper.like(TestModelParam::getProjectName, projectName);
        }
        if (StringUtils.isNotBlank(projectManager)) {
            List<OaUserParam> params = oaUserService.lambdaQuery().like(OaUserParam::getName, projectManager).list();
            if (CollectionUtil.isNotEmpty(params)) {
                List<String> tn = new ArrayList<>();
                for (OaUserParam param : params) {
                    tn.add(param.getId() + "");
                }
                testModelParamLambdaQueryWrapper.in(TestModelParam::getProjectManager, tn);
            }
        }
        testModelParamLambdaQueryWrapper.orderByDesc(TestModelParam::getCreateTime);
        Page<TestModelParam> page = testModelParamService.page(testModelParamPage, testModelParamLambdaQueryWrapper);
        List<TestModelParam> records = page.getRecords();
        //将查询到的所有实体对象封装到Vo中
        List<TestModelParamToVo> outputRecords = new ArrayList<>();
        for (int i = 0; i < records.size(); i++) {
            TestModelParamToVo vo = new TestModelParamToVo();
            BeanUtils.copyProperties(records.get(i), vo);
            if (null == records.get(i).getVersion()) {
                vo.setEdition("V1");
            } else {
                vo.setEdition("V" + records.get(i).getVersion());
            }
            if (StringUtils.isNotBlank(vo.getTongmanName())) {
                vo.setTongmanNameName(oaUserService.getOaUserName(vo.getTongmanName()));
            } else {
                vo.setTongmanNameName("");
            }
            if (StringUtils.isNotBlank(vo.getProjectManager())) {
                vo.setProjectManagerName(oaUserService.getOaUserName(vo.getProjectManager()));
            } else {
                vo.setProjectManagerName("");
            }
            if (StringUtils.isNumeric(vo.getTongmanId()) && StringUtils.isNumeric(vo.getTongmanName())) {
                JSONArray array = new JSONArray();
                array.add(Integer.valueOf(vo.getTongmanId()));
                array.add(Integer.valueOf(vo.getTongmanName()));
                vo.setTongmanArray(array);
            } else {
                vo.setTongmanArray(new JSONArray());
            }
            if (StringUtils.isNumeric(vo.getProjectManagerId()) && StringUtils.isNumeric(vo.getProjectManager())) {
                JSONArray array = new JSONArray();
                array.add(Integer.valueOf(vo.getProjectManagerId()));
                array.add(Integer.valueOf(vo.getProjectManager()));
                vo.setProjectArray(array);
            } else {
                vo.setProjectArray(new JSONArray());
            }
            if (StringUtils.isNumeric(vo.getDesignerUserId()) && StringUtils.isNumeric(vo.getDesignerUserId())) {
                JSONArray array = new JSONArray();
                array.add(Integer.valueOf(vo.getDesignerUnitId()));
                array.add(Integer.valueOf(vo.getDesignerUserId()));
                vo.setMoldDesigner(array);
            } else {
                vo.setMoldDesigner(new JSONArray());
            }

            //查看图片
            List<TestImage> testImageList = testImageMapper.selectList(new LambdaQueryWrapper<TestImage>()
                    .eq(TestImage::getType, 0)
                    .eq(TestImage::getSceneId, vo.getMoldId())
                    .orderByAsc(TestImage::getCreateTime));
            vo.setAnnouncementsImages(testImageList.stream().map(x -> x.getUrl()).toArray(String[]::new));

            outputRecords.add(vo);
        }
        Map<String, Object> result = new HashMap<>();
        result.put("dataList", outputRecords);
        result.put("totalNum", page.getTotal());
        return JSON.toJSONString(R.data(result));
    }

    @Override
    public String addMold(JSONObject jsonObject) {
        //将jsonObject对象转换为java的对象
        TestModelParamVo testMoldParamVo = JSON.toJavaObject(jsonObject, TestModelParamVo.class);
        TestModelParam modelParam = new TestModelParam();
        BeanUtils.copyProperties(testMoldParamVo, modelParam);
        if (StringUtils.isNotBlank(modelParam.getTongmanName())) {
            JSONArray array = JSONArray.parseArray(modelParam.getTongmanName());
            modelParam.setTongmanId(array.getString(0));
            modelParam.setTongmanName(array.getString(1));
        }
        if (StringUtils.isNotBlank(modelParam.getProjectManager())) {
            JSONArray array = JSONArray.parseArray(modelParam.getProjectManager());
            modelParam.setProjectManagerId(array.getString(0));
            modelParam.setProjectManager(array.getString(1));
        }
        if (CollectionUtil.isNotEmpty(testMoldParamVo.getMoldDesigner())) {
            modelParam.setDesignerUnitId(testMoldParamVo.getMoldDesigner().getString(0));
            modelParam.setDesignerUserId(testMoldParamVo.getMoldDesigner().getString(1));
        }
        //需要单独设置一些属性
        Date date = new Date();
        modelParam.setCreateTime(date);
        modelParam.setUpdateTime(date);
        modelParam.setProductSize(testMoldParamVo.getProductLength() + "*" + testMoldParamVo.getProductWidth() + "*" + testMoldParamVo.getProductHeight());
        modelParam.setMoldSize(testMoldParamVo.getMoldLength() + "*" + testMoldParamVo.getMoldWidth() + "*" + testMoldParamVo.getMoldHeight());
        String moldId = testMoldParamVo.getMoldId();
        //判断数据库中是否已经存在将要添加的模具编号
        TestModelParam result = testModelParamService.getOne(new LambdaQueryWrapper<TestModelParam>().eq(TestModelParam::getMoldId, moldId));
        if (result != null) {
            return JSON.toJSONString(R.fail("模具编号已存在"));
        }
        modelParam.setVersion(1);
        testModelParamService.save(modelParam);
        //保存图片
        if (Objects.nonNull(testMoldParamVo.getAnnouncementsImages())) {
            List<TestImage> testImageList = Arrays.stream(testMoldParamVo.getAnnouncementsImages()).map(url -> {
                        TestImage testImage = new TestImage();
                        testImage.setType(0);
                        testImage.setSceneId(modelParam.getMoldId());
                        testImage.setUrl(url);
                        return testImage;
                    })
                    .collect(Collectors.toList());
            testImageService.saveBatch(testImageList);
        }

        return JSON.toJSONString(R.success("保存成功"));
    }

    @Override
    @Transactional
    public synchronized String editMold(JSONObject jsonObject, HttpServletRequest request) {
        //将jsonObject对象转换为java的对象
        TestModelParamToVo testMoldParamVo = JSON.toJavaObject(jsonObject, TestModelParamToVo.class);
        TestModelParam one = testModelParamService
                .lambdaQuery()
                .eq(TestModelParam::getMoldId, testMoldParamVo.getUnchangedMoldId())
                .one();
        if (ObjectUtil.isEmpty(one)) {
            return JSON.toJSONString(R.fail("模具已删除/不存在"));
        }
        if (!testMoldParamVo.getMoldId().equals(testMoldParamVo.getUnchangedMoldId())) {
            if (testModelSubTableService
                    .lambdaQuery()
                    .eq(TestModelSubTable::getMoldId, testMoldParamVo.getUnchangedMoldId()).count() > 0) {
                return JSON.toJSONString(R.fail("该模具已试模，模具编号暂不可修改"));
            }
            one = testModelParamService
                    .lambdaQuery()
                    .eq(TestModelParam::getMoldId, testMoldParamVo.getMoldId())
                    .one();
            if (ObjectUtil.isNotEmpty(one)) {
                return JSON.toJSONString(R.fail("模具编号已存在"));
            }
            testModelParamService.update(null,
                    new UpdateWrapper<TestModelParam>()
                            .lambda()
                            .set(TestModelParam::getMoldId, testMoldParamVo.getMoldId())
                            .eq(TestModelParam::getMoldId, testMoldParamVo.getUnchangedMoldId())
            );
            one = testModelParamService
                    .lambdaQuery()
                    .eq(TestModelParam::getMoldId, testMoldParamVo.getMoldId())
                    .one();
            if (ObjectUtil.isEmpty(one)) {
                return JSON.toJSONString(R.fail("模具已删除/不存在"));
            }
        }
        TestModelParam modelParam = new TestModelParam();
        BeanUtils.copyProperties(testMoldParamVo, modelParam);
        if (CollectionUtil.isNotEmpty(testMoldParamVo.getTongmanArray())) {
            modelParam.setTongmanId(testMoldParamVo.getTongmanArray().getString(0));
            modelParam.setTongmanName(testMoldParamVo.getTongmanArray().getString(1));
        }
        if (CollectionUtil.isNotEmpty(testMoldParamVo.getProjectArray())) {
            modelParam.setProjectManagerId(testMoldParamVo.getProjectArray().getString(0));
            modelParam.setProjectManager(testMoldParamVo.getProjectArray().getString(1));
        }
        //需要单独设置一些属性
        modelParam.setUpdateTime(new Date());
        modelParam.setProductSize(testMoldParamVo.getProductLength() + "*" + testMoldParamVo.getProductWidth() + "*" + testMoldParamVo.getProductHeight());
        modelParam.setMoldSize(testMoldParamVo.getMoldLength() + "*" + testMoldParamVo.getMoldWidth() + "*" + testMoldParamVo.getMoldHeight());
        SystemHeader header = MyUtils.getHeader(request);
        int vs = 1;
        if (null != one.getVersion()) {
            vs = one.getVersion() + 1;
        }
        List<Edtion> edtions = EdtionVerity.updateMoldEdtion(
                testMoldParamVo,
                one,
                vs,
                header.getId()
        );
        if (StringUtils.isNotBlank(modelParam.getTongmanName())) {
            if (null != modelParam.getTongmanName() && !modelParam.getTongmanName().equals(one.getTongmanName())) {
                Edtion edtion = new Edtion();
                edtion.setRed_id(modelParam.getMoldId());
                edtion.setEdition("V" + vs);
                edtion.setKeyName("tongmanName");
                edtion.setKeyValue("钳工");
                edtion.setBaseValue(oaUserService.getOaUserName(one.getTongmanName()));
                edtion.setUpdateValue(oaUserService.getOaUserName(modelParam.getTongmanName()));
                edtion.setPerson(header.getId());
                edtions.add(edtion);
            }
        }
        if (StringUtils.isNotBlank(modelParam.getProjectManager())) {
            if (null != modelParam.getProjectManager() && !modelParam.getProjectManager().equals(one.getProjectManager())) {
                Edtion edtion = new Edtion();
                edtion.setRed_id(modelParam.getMoldId());
                edtion.setEdition("V" + vs);
                edtion.setKeyName("projectManager");
                edtion.setKeyValue("主要联络人");
                edtion.setBaseValue(oaUserService.getOaUserName(one.getProjectManager()));
                edtion.setUpdateValue(oaUserService.getOaUserName(modelParam.getProjectManager()));
                edtion.setPerson(header.getId());
                edtions.add(edtion);
            }
        }
        if (CollectionUtil.isNotEmpty(testMoldParamVo.getMoldDesigner())) {
            modelParam.setDesignerUnitId(testMoldParamVo.getMoldDesigner().getString(0));
            modelParam.setDesignerUserId(testMoldParamVo.getMoldDesigner().getString(1));
            if (!modelParam.getDesignerUserId().equals(one.getDesignerUserId())) {
                Edtion edtion = new Edtion();
                edtion.setRed_id(modelParam.getMoldId());
                edtion.setEdition("V" + vs);
                edtion.setKeyName("moldDesigner");
                edtion.setKeyValue("项目设计人");
                edtion.setBaseValue(oaUserService.getOaUserName(one.getDesignerUserId()));
                edtion.setUpdateValue(oaUserService.getOaUserName(modelParam.getDesignerUserId()));
                edtion.setPerson(header.getId());
                edtions.add(edtion);
            }
        }
        if (null != testMoldParamVo.getMachineSize()
                && !testMoldParamVo.getMachineSize().equals(one.getMachineSize())) {
            Edtion edtion = new Edtion();
            edtion.setRed_id(testMoldParamVo.getMoldId());
            edtion.setEdition("V" + vs);
            edtion.setKeyName("machineSize");
            edtion.setKeyValue("机台大小");

            String oldValue = one.getMachineSize();
            TryOutDeviceMod old = tryOutDeviceModService.getById(one.getMachineSize());
            if (ObjectUtil.isNotEmpty(old)) {
                oldValue = old.getDeviceName();
            }
            edtion.setBaseValue(oldValue);

            String newValue = testMoldParamVo.getMachineSize();
            TryOutDeviceMod newMod = tryOutDeviceModService.getById(testMoldParamVo.getMachineSize());
            if (ObjectUtil.isNotEmpty(newMod)) {
                newValue = newMod.getDeviceName();
            }
            edtion.setUpdateValue(newValue);

            edtion.setPerson(header.getId());
            edtions.add(edtion);
        }
        if (StringUtils.isNotBlank(testMoldParamVo.getCustomerName())
                && !testMoldParamVo.getCustomerName().equals(one.getCustomerName())) {
            String old = "";
            String newId = "";
            DictTable dictTable = dictTableService.getById(one.getCustomerName());
            if (ObjectUtil.isNotEmpty(dictTable)) {
                old = dictTable.getDicName();
            } else {
                old = one.getCustomerName();
            }
            dictTable = dictTableService.getById(testMoldParamVo.getCustomerName());
            if (ObjectUtil.isNotEmpty(dictTable)) {
                newId = dictTable.getDicName();
                Edtion edtion = new Edtion();
                edtion.setRed_id(testMoldParamVo.getMoldId());
                edtion.setEdition("V" + vs);
                edtion.setKeyName("customerName");
                edtion.setKeyValue("客户");
                edtion.setBaseValue(old);
                edtion.setUpdateValue(newId);
                edtion.setPerson(header.getId());
                edtions.add(edtion);
            }
        }
        if (StringUtils.isNotBlank(testMoldParamVo.getPartsFactoryId())
                && !testMoldParamVo.getPartsFactoryId().equals(one.getPartsFactoryId())) {
            String old = "";
            String newId = "";
            DictTable dictTable = dictTableService.getById(one.getPartsFactoryId());
            if (ObjectUtil.isNotEmpty(dictTable)) {
                old = dictTable.getDicName();
            }
            dictTable = dictTableService.getById(testMoldParamVo.getPartsFactoryId());
            if (ObjectUtil.isNotEmpty(dictTable)) {
                newId = dictTable.getDicName();
                Edtion edtion = new Edtion();
                edtion.setRed_id(testMoldParamVo.getMoldId());
                edtion.setEdition("V" + (vs + 1));
                edtion.setKeyName("partsFactoryId");
                edtion.setKeyValue("零件厂");
                edtion.setBaseValue(old);
                edtion.setUpdateValue(newId);
                edtion.setPerson(header.getId());
                edtions.add(edtion);
            }
        }
        if (CollectionUtil.isNotEmpty(edtions)) {
            edtionService.saveBatch(edtions);
            modelParam.setVersion(vs);
        }
        //根据id更新某条数据
        boolean b = testModelParamService.updateById(modelParam);
        if (b) {
            //保存图片
            if (Objects.nonNull(testMoldParamVo.getAnnouncementsImages())) {
                testImageMapper.delete(new LambdaUpdateWrapper<TestImage>().eq(TestImage::getType, 0).eq(TestImage::getSceneId, testMoldParamVo.getMoldId()));
                List<TestImage> testImageList = Arrays.stream(testMoldParamVo.getAnnouncementsImages()).map(url -> {
                            TestImage testImage = new TestImage();
                            testImage.setType(0);
                            testImage.setSceneId(modelParam.getMoldId());
                            testImage.setUrl(url);
                            return testImage;
                        })
                        .collect(Collectors.toList());
                testImageService.saveBatch(testImageList);
            }

            return JSON.toJSONString(R.success("保存成功"));
        }

        return JSON.toJSONString(R.fail("保存失败"));
    }


    @Override
    public String deleteMold(JSONObject jsonObject) {
        //jsonobject解析获取模具Id
        String Id = jsonObject.getString("moldId");
        if (testModelSubTableService.lambdaQuery().eq(TestModelSubTable::getMoldId, Id).count() > 0) {
            return JSON.toJSONString(R.fail("该模具已试模，不可删除"));
        }
        boolean b = testModelParamService.removeById(Id);
        if (b) {
            edtionService.remove(new LambdaQueryWrapper<Edtion>().eq(Edtion::getRed_id, Id));
            return JSON.toJSONString(R.success("删除成功"));
        }
        return JSON.toJSONString(R.fail("数据已存在/不存在"));
    }

    @Override
    public String queryMoldByName(JSONObject jsonObject) {
        //jsonobject解析获取模具编号
        String moldId = jsonObject.getString("moldId");
        //jsonobject解析获取模具名称
        String moldName = jsonObject.getString("moldName");
        List<TestModelParamToVo> list = new ArrayList<>();
        HashMap<String, Object> result = new HashMap<>();
        Page<TestModelParam> testModelParamPage = new Page<>(1, 99999);
        //根据传入的字段决定不同的操作
//        if (StringUtils.isNotEmpty(moldId)) {
//            testModelParam = testModelParamService.getById(moldId);
//            if (testModelParam != null) {
//                TestModelParamToVo testModelParamVo = new TestModelParamToVo();
//                BeanUtils.copyProperties(testModelParam, testModelParamVo);
//                if (StringUtils.isNotBlank(testModelParamVo.getTongmanId())) {
//                    JSONArray array = new JSONArray();
//                    array.add(testModelParamVo.getTongmanId());
//                    array.add(testModelParamVo.getTongmanName());
//                    testModelParamVo.setTongmanArray(array);
//                }
//                if (StringUtils.isNotBlank(testModelParamVo.getProjectManagerId())) {
//                    JSONArray array = new JSONArray();
//                    array.add(testModelParamVo.getProjectManagerId());
//                    array.add(testModelParamVo.getProjectManager());
//                    testModelParamVo.setProjectArray(array);
//                }
//                list.add(testModelParamVo);
//            }
//        } else
        if (StringUtils.isNotEmpty(moldId) || StringUtils.isNotEmpty(moldName)) {
            LambdaQueryWrapper<TestModelParam> testModelParamLambdaQueryWrapper = new LambdaQueryWrapper<>();
            //根据名称模糊查询所有符合的数据
            if (StringUtils.isNotEmpty(moldId)) {
                testModelParamLambdaQueryWrapper.like(TestModelParam::getMoldId, moldId);
            }
            if (StringUtils.isNotEmpty(moldName)) {
                testModelParamLambdaQueryWrapper.like(TestModelParam::getMoldName, moldName);
            }
            Page<TestModelParam> page = testModelParamService.page(testModelParamPage, testModelParamLambdaQueryWrapper);
            List<TestModelParam> records = page.getRecords();
            //封装数据到Vo对象
            for (int i = 0; i < records.size(); i++) {
                TestModelParam modelParam = records.get(i);
                if (ObjectUtil.isNotEmpty(modelParam)) {
                    TestModelParamToVo vo = new TestModelParamToVo();
                    BeanUtils.copyProperties(modelParam, vo);
                    if (StringUtils.isNotBlank(vo.getTongmanName())) {
                        vo.setTongmanNameName(oaUserService.getOaUserName(vo.getTongmanName()));
                    }
                    if (StringUtils.isNotBlank(vo.getProjectManager())) {
                        vo.setProjectManagerName(oaUserService.getOaUserName(vo.getProjectManager()));
                    }
                    if (StringUtils.isNotBlank(vo.getTongmanId())) {
                        JSONArray array = new JSONArray();
                        array.add(vo.getTongmanId());
                        array.add(vo.getTongmanName());
                        vo.setTongmanArray(array);
                    }
                    if (StringUtils.isNotBlank(vo.getProjectManagerId())) {
                        JSONArray array = new JSONArray();
                        array.add(vo.getProjectManagerId());
                        array.add(vo.getProjectManager());
                        vo.setProjectArray(array);
                    }
                    list.add(vo);
                }
            }
        } else {
            //如果传入为空，则默认查询
            Page<TestModelParam> page = testModelParamService.page(testModelParamPage);
            List<TestModelParam> records = page.getRecords();
            //将查询结果封装到Vo对象中
            for (int i = 0; i < records.size(); i++) {
                TestModelParam modelParam = records.get(i);
                if (ObjectUtil.isNotEmpty(modelParam)) {
                    TestModelParamToVo vo = new TestModelParamToVo();
                    BeanUtils.copyProperties(modelParam, vo);
                    if (StringUtils.isNotBlank(vo.getTongmanName())) {
                        vo.setTongmanNameName(oaUserService.getOaUserName(vo.getTongmanName()));
                    }
                    if (StringUtils.isNotBlank(vo.getProjectManager())) {
                        vo.setProjectManagerName(oaUserService.getOaUserName(vo.getProjectManager()));
                    }
                    if (StringUtils.isNotBlank(vo.getTongmanId())) {
                        JSONArray array = new JSONArray();
                        array.add(vo.getTongmanId());
                        array.add(vo.getTongmanName());
                        vo.setTongmanArray(array);
                    }
                    if (StringUtils.isNotBlank(vo.getProjectManagerId())) {
                        JSONArray array = new JSONArray();
                        array.add(vo.getProjectManagerId());
                        array.add(vo.getProjectManager());
                        vo.setProjectArray(array);
                    }
                    list.add(vo);
                }
            }
        }
        if (!list.isEmpty()) {
            List<String> moldIdList = list.parallelStream().map(x -> x.getMoldId()).collect(Collectors.toList());
            List<TestImage> testImageList = testImageMapper.selectList(new LambdaQueryWrapper<TestImage>()
                    .eq(TestImage::getType, 0)
                    .in(TestImage::getSceneId, moldIdList)
                    .orderByAsc(TestImage::getCreateTime));
            result.put("announcementsImages", testImageList.stream().map(x -> x.getUrl()).collect(Collectors.toList()));
        }


        result.put("dataList", list);
        return JSON.toJSONString(R.data(result));
    }
}
